package dq.study.redis.pipeline;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Random;

/**
 * @author dongqun
 * @version 1.0.0
 * @since 2021/12/09 11:11:00
 */
@Component
public class BigBatHandler {
    @Autowired
    private RedisTemplate redisTemplate;

    @PostConstruct
    public void handler() {
        long start = System.currentTimeMillis();
        redisTemplate.executePipelined((RedisCallback<Object>) redisConnection -> {
            Random random = new Random();
            for (int i = 0; i < 1000; i++) {
                redisConnection.lPush("rlk2".getBytes(), "sss".getBytes());
            }
            return null;
        });
        long end = System.currentTimeMillis();
        System.out.println("pipeline list lpush time:" + (end - start));
    }
}
